package page

const DefaultPageSize = 25 // 默认每页大小

type Collection[T any] struct {
	Total     int64  `json:"total"`
	Page      uint64 `json:"page"`
	PageSize  uint64 `json:"page_size"`
	List      []T    `json:"list"`
	TotalPage uint64 `json:"total_page"`
}

// PageToOffset converts page and pageSize to offset.
func PageToOffset(page, pageSize uint64) uint64 {
	return (page - 1) * pageSize
}

func GetTotalPage(page, pageSize uint64, total int64) (totalPage uint64) {
	if pageSize == 0 {
		pageSize = 15
	}
	if page == 0 {
		page = 1
	}
	if uint64(total)%pageSize == 0 {
		totalPage = uint64(total) / pageSize
	} else {
		totalPage = uint64(total)/pageSize + 1
	}
	return
}
